/*
 * Copyright 2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.gitee.joyz.api.result.logging;

import org.slf4j.Logger;

import java.util.function.Supplier;

/**
 * 自定义日志类
 * <p>对slf4j 日志类进行封装
 *
 * @author JoyZ
 */
public class Log {

    private final Logger logger;

    /**
     * 构造器
     *
     * @param logger Logger 实例
     */
    public Log(Logger logger) {
        this.logger = logger;
    }

    /**
     * 错误
     *
     * @param msg      消息
     * @param supplier 异常
     */
    public void error(String msg, Supplier<Throwable> supplier) {
        logger.error(msg, supplier.get());
    }

    /**
     * 错误
     *
     * @param msg 消息
     */
    public void error(String msg) {
        logger.error(msg);
    }

    /**
     * 警告
     *
     * @param msg      消息
     * @param supplier 异常
     */
    public void warn(String msg, Supplier<Throwable> supplier) {
        logger.warn(msg, supplier.get());
    }

    /**
     * 警告
     *
     * @param msg 消息
     */
    public void warn(String msg) {
        logger.warn(msg);
    }

    /**
     * 信息
     *
     * @param msg 消息
     */
    public void info(String msg) {
        logger.info(msg);
    }

    /**
     * 信息
     *
     * @param msg      消息
     * @param supplier 异常
     */
    public void info(String msg, Supplier<Throwable> supplier) {
        logger.info(msg, supplier.get());
    }

    /**
     * 调试
     *
     * @param msg 消息
     */
    public void debug(String msg) {
        if (logger.isDebugEnabled()) {
            logger.debug(msg);
        }
    }

    /**
     * 跟踪
     *
     * @param msg 消息
     */
    public void trace(String msg) {
        if (logger.isTraceEnabled()) {
            logger.trace(msg);
        }
    }
}
